package homework;
import java.util.Random;
import java.util.Scanner;
public class Test11 {
    public static void main(String[] args) {
        Random random=new Random();
        int[] a=new int[4];
        while (true) {
            for (int i= 0; i < 4; i++) {
                switch (random.nextInt(3)+1){
                    case 1:a[i]=random.nextInt(26)+65;break;
                    case 2:a[i]=random.nextInt(26)+97;break;
                    case 3:a[i]=random.nextInt(10)+48;break;
                }
            }
            System.out.println(toChar(a));
            System.out.println("请输入验证码");

            if (new Scanner(System.in).nextLine().equals(toChar(a))){
                System.out.println("验证码正确");
                break;
            }else{
                System.out.println("输入错误，验证码已更新");
            }
        }
    }
    public static String toChar(int[] ints){
        System.out.print("验证码为:");
        StringBuilder sb =new StringBuilder();
        for (int i = 0; i < ints.length; i++) {
            char[] chars=new char[ints.length];
            chars[i]=(char) ints[i];
            sb.append(chars[i]);
        }
        return sb.toString();
    }
}
